package com.hs.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Coursetype;
import com.hs.sfzy.entity.Heartknowledge;
import com.hs.sfzy.service.CoursetypeService;
import com.hs.sfzy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: sfzyBackEnd
 * @BelongsPackage: com.hs.sfzy.controller
 * @ClassName CoursetypeController
 * @Author: 陈千鱼不是鱼
 * @CreateTime: 2024-10-25  20:44
 * @Description:课程类型控制层
 * @Version: 1.0
 */
@RestController
@RequestMapping("/coursetype")
@Api(tags = "课程分类")
@RequiredArgsConstructor
public class CoursetypeController {

    private final CoursetypeService coursetypeService;

    @GetMapping("/findAll")
    @ApiOperation("课程查询")
    public Result<List<Coursetype> > findAll() {
        return Result.success(coursetypeService.findAll());
    }

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result page(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "5") Integer pageSize,
            @ApiParam("课程分类名字") String name
    ) {
        PageInfo<Coursetype> info = coursetypeService.page(pageNum,pageSize,name);

        return Result.success(info);
    }

    @PostMapping("/save")
    @ApiOperation("新增课程分类")
    public Result save(@RequestBody Coursetype coursetype) {
        coursetypeService.save(coursetype);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除课程分类")
    public Result deleteById(@PathVariable("id") Integer id) {
        coursetypeService.deleteById(id);
        return Result.success();
    }

    @PutMapping("/update")
    @ApiOperation("更新心理知识")
    public Result update(@RequestBody Coursetype coursetype) {
        coursetypeService.update(coursetype);
        return Result.success();
    }

}
